<?php

$server = new Swoole\Server('0.0.0.0',8080);

$server->set(['task_worker_num' => 4]);

$server->on('receive',function($server,$fd,$from_id,$data){
	$task_id = $server->task($data);
	echo "Dispatch AsyncTask: id=$task_id\n";
});

$server->on('task',function($server,$task_id,$from_id,$data){
	echo "New AsyncTask[id = $task_id]".PHP_EOL;
	sleep(2);
	$server->finish("$data -> OK");
});

$server->on('finish',function($server,$task_id,$data){
	echo "AsyncTak[$task_id] Finish:{$data}".PHP_EOL;
});

$server->start();

